/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.rw.magallanes.ide.controller;

import com.rw.magallanes.core.Category;
import com.rw.magallanes.core.Item;
import com.rw.magallanes.core.Warehouse;
import com.rw.magallanes.ide.main.MainFrame;
import com.rw.magallanes.ide.main.MainSystem;
import com.rw.magallanes.utilities.MessageType;
import com.rw.magallanes.utilities.Utilities;

/**
 *
 * @author Gonzalez
 */
public class ItemController {

    public static void setName(Item item, String strValue) {
        MainSystem ms = MainSystem.getInstance();
        MainFrame mf = ms.getMainFrame();
        Warehouse wh = mf.getWarehouse();

        if (!strValue.isEmpty()) {
            strValue = strValue.trim();
            if (strValue.compareTo(item.getName()) != 0) {
                if (!wh.existsItemName(strValue)) {
                    item.setName(strValue);
                } else {
                    Utilities.showMsg(mf, "El item ya existe", MessageType.WARN);
                }
            }
        } else {
            Utilities.showMsg(mf, "Nombre no valido", MessageType.WARN);
        }
    }

    public static void setCategory(Item item, Category category) {
        item.setCategory(category);
    }

    public static void setPrice(Item item, double dblValue) {
        MainSystem ms = MainSystem.getInstance();
        MainFrame mf = ms.getMainFrame();

        if (dblValue >= 0) {
            item.setPrice(dblValue);
        } else {
            Utilities.showMsg(mf, "Precio invalido", MessageType.WARN);
        }
    }

    public static void setCount(Item item, int intValue) {
        MainSystem ms = MainSystem.getInstance();
        MainFrame mf = ms.getMainFrame();

        if (intValue >= 0) {
            item.setCount(intValue);
        } else {
            Utilities.showMsg(mf, "Cantidad invalida", MessageType.WARN);
        }
    }
}
